<template>
  <div style="padding-right: 30px;padding-top:30px">
    <el-form :rules="rules" :model="ruleForm" label-width="110px" ref="ruleForm" label-position="left">
      <el-form-item label="配送线路名称" prop="name">
        <el-input  clearable
        style="width:100%"
        class="inline-input"
        v-model="ruleForm.name"
        placeholder="请输入线路名称"/>
      </el-form-item>
      <el-form-item label="默认车辆" prop="vehicleCode">
        <el-select v-model="ruleForm.vehicleCode" filterable placeholder="点击或输入选择" style="width:100%" clearable>
          <el-option
            v-for="item in options"
            :key="item.code"
            :label="item.licenseNumber"
            :value="item.code">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="描述" prop="description">
        <el-input v-model="ruleForm.description" clearable placeholder="请输入描述内容"></el-input>
      </el-form-item>
      <el-form-item style="margin-top:50px">
        <el-button type="primary" @click="funcSubmit">立即处理</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
  import {addShipmentLine} from "@/api/shipment";
  import request from '@/utils/request'
  export default {
    name: "Edit",
    data() {
      return {
        ruleForm: {
          shipmentUserCode: '',
          description: '',
          vehicleCode: '',
          name: ''
        },
        rules: {
          name: [
            {required: true, message: '请输入线路名称', trigger: 'blur'},
            {min: 1, max: 50, message: '长度在 1 到 50 个字符', trigger: 'blur'}
          ]
        },
        options: [],
        value: '', 
      };
    },
    created() {
      this.getVehicleList();
      let shipmentUserCode = this.$route.query.partyCode
      this.ruleForm.shipmentUserCode = shipmentUserCode;
    },
    methods: {
      getVehicleList() {
        request({url: `/ntocc-basic-api/vehicle/list`, method: 'get'}).then(response => {
          this.options = response.data
        })
      },
      funcSubmit() {
        this.$refs['ruleForm'].validate((valid) => {
          if (valid) {
            const rLoading = this.openLoading();
            addShipmentLine(this.ruleForm).then(response => {
              rLoading.close();
              this.$message({message: response.msg, type: 'success'})
              this.$emit('hideModel')
            })
          } else {
            return false
          }
        })
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  };
</script>
